﻿@{
    
    Layout = "~/Shared/Layouts/_Layout.cshtml";
    Page.Title = "Ресетирај Лозинка";
    
    var resetToken = Request["resetToken"] ?? "";
    var message = "";
    var newPassword1 = "";
    var newPassword2 = "";
    
    if(IsPost) {
        newPassword1 = Request["newPassword1"];
        newPassword2 = Request["newPassword2"];
        
        // Validation       
        if (newPassword1.IsEmpty()) {
            ModelState.AddError("newPassword1", "Задожително.");
        }
        
        if (newPassword2.IsEmpty()) {
            ModelState.AddError("newPassword2", "Задожително.");
        }
        
        if(newPassword1 != newPassword2)
        {
            ModelState.AddError("newPassword1", "Лозинките не се совпаѓаат.");
        }
        
        // Attempt password reset        
        if(ModelState.IsValid)
        {
            if (WebSecurity.ResetPassword(resetToken, newPassword1))
            {
                message = "Успешна промена на лозинката.";
            }
            else
            {
                message = "Неуспешна промена на лозинката.";
            }
        }
  }
}

<h1>Ресетирај Лозинка</h1>
@if (!message.IsEmpty()) {
    <p>@message</p>
}
else
{
    <form action="PasswordReset" method="post" class="accountForm">
        @Html.Hidden("resetToken", resetToken)
        <p>
            @Html.Label("Нова Лозинка: ", "newPassword1")<br />
            @Html.Password("newPassword1", newPassword1)
            @Html.ValidationMessage("newPassword1")
        </p>
        <p>
            @Html.Label("Потврди Нова Лозинка: ", "newPassword2")<br />
            @Html.Password("newPassword2", newPassword2)
            @Html.ValidationMessage("newPassword2")
        </p>
        <p>
            <input type="submit" value="Ресетирај Лозинка" />
        </p>
    </form>
}


